<?php

namespace common\model;

use think\model\RelationModel;

class MediaModel extends RelationModel
{
    //自动验证
    protected $_validate = [
        ['link_id', '', '', self::EXISTS_VALIDATE, 'integer', self::MODEL_BOTH],//必须字段
        ['module', '1,64', '', self::EXISTS_VALIDATE, 'length'],
        ['md5_name', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['md5_name', '1,255', '', self::EXISTS_VALIDATE, 'length'],
        ['size', '0,255', '', self::EXISTS_VALIDATE, 'length'],
        ['type', '1,36', '', self::EXISTS_VALIDATE, 'length'],

    ];

    // 自动完成
    protected $_auto = [
        ['created_by', 'fill_created_by', self::MODEL_INSERT, 'function'],
        ['created', 'time', self::MODEL_INSERT, 'function'],
        ['uuid', 'create_uuid', self::MODEL_INSERT, 'function'],
        ['param', 'json_encode', self::EXISTS_VALIDATE, 'function'],
    ];

    /**
     * 获取器：创建时间
     * @param $value
     * @param $data
     * @return array|mixed
     */
//    public function getCreatedAttr($value, $data)
//    {
//        if (!empty($value)) {
//            return get_format_date($value, 1);
//        }
//        return "";
//    }

    /**
     * 获取器: 媒体详细参数
     * @param $value
     * @param $data
     * @return array|mixed
     */
    public function getParamAttr($value, $data)
    {
        if (empty($value)) {
            return [];
        }
        return json_decode($value, true);
    }
}
